<?php


namespace app\common\service\message\course;


use app\common\service\message\Basics;

class Remain extends Basics
{

    protected $param = [
        'apply' => [],   // 申请记录
        'user' => [],    // 用户信息
    ];

    public function send($param)
    {
        // TODO: Implement send() method.
        // 记录参数
        $this->param = $param;
        // 微信订阅消息通知用户
        $this->onSendWxSubMsg();
    }

    private function onSendWxSubMsg()
    {
        $reservationInfo = $this->param['reservation'];
        $userInfo = $reservationInfo['user'];
        $wxappId = $reservationInfo['wxapp_id'];

        $start = date('H:i',strtotime($reservationInfo['start_time']));
        $end = date('H:i',strtotime($reservationInfo['end_time']));

        // 发送订阅消息
        return $this->sendWxSubMsg($wxappId,[
            'touser' => $userInfo['open_id'],
            'template_id' => '9CqeF6dltymSS_J2wDDMo0aaWhWIJRwNRNaEz7CKTWM',
            'page' => '',
            'data' => [
                // 课程名称
                'thing6' => ['value' => $reservationInfo['course']['course_name']],
                // 预约门店
                'thing13' => ['value' => $reservationInfo['shop']['shop_name']],
                // 教练
                'name9' => ['value' => $reservationInfo['coach']['real_name']],
                // 课程类型
                'thing2' => ['value' => $reservationInfo['course']['type']['text']],
                // 课程时间
                'date7' => ['value' =>$reservationInfo['date']." ".$start."~".$end],
            ],
        ]);
    }
}